package com.soft.javase.day09;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/4/29
 */
public class CharCount {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个字符串：");
        String str = sc.nextLine();
        Map<Character, Integer> charCountMap = new HashMap<>();

        for (char c : str.toCharArray()) {
            charCountMap.put(c, charCountMap.getOrDefault(c, 0) + 1);
        }

        for (Map.Entry<Character, Integer> entry : charCountMap.entrySet()) {
            System.out.println("字符 '" + entry.getKey() + "' 出现次数: " + entry.getValue());
        }
    }

}
